package com.dixiang.framework.http;

import java.util.Map;
import android.app.Activity;
import android.content.Context;
import android.util.Log;

import com.dixiang.framework.common.QJNetUICallback;
import com.dixiang.framework.config.SystemConfig;
import com.dixiang.framework.network.IResult;
import com.dixiang.framework.network.Net;
import com.dixiang.framework.network.URLHandler;
import com.dixiang.framework.utils.Utils;
import com.google.gson.reflect.TypeToken;

public class HttpAccess {

	public static <T extends IResult> String getDataObject(Activity activity,
			String url, Map<String, Object> map, TypeToken typeToken,
			QJNetUICallback callback) {
		if (Utils.isStringEmpty(url))
			return "";
//		LoadingDialog.getInstance(activity).show();
		String path = URLHandler.getEncryptUrl(url);
		Net.with(activity).fetch(path, map, typeToken, callback);
		return path;
	}

	public static <T extends IResult> String getCheckData(Context activity,
			Map<String, Object> map, TypeToken typeToken,
			QJNetUICallback callback) {
//		LoadingDialog.getInstance(activity).show();
		String path = URLHandler.getEncryptUrl(SystemConfig.DATA_VERSION);
		Net.with(activity).fetch(path, map, typeToken, callback);
		return path;
	}

	public static <T extends IResult> String getLocalData(Context activity,
			String url, Map<String, Object> map, TypeToken typeToken,
			QJNetUICallback callback) {
		if (Utils.isStringEmpty(url)) {
			url = SystemConfig.DATA_LOCALDATA;
		}
//		LoadingDialog.getInstance(activity).show();

		String path = URLHandler.getEncryptUrl(url);
		Net.with(activity).fetch(path, map, typeToken, callback);
		return path;
	}

	public static <T extends IResult> String postDataObject(Activity activity,
			String url, Map<String, Object> map, TypeToken typeToken,
			QJNetUICallback callback) {
		if (Utils.isStringEmpty(url))
			return "";
//		LoadingDialog.getInstance(activity).show();
		String path = URLHandler.getPostEncryptUrl(url);
		if (map != null) {
			map.put("sign", URLHandler.getPostSignParam(path));
			Log.e("sign", URLHandler.getPostSignParam(path));
		}
		Net.with(activity).fetch(path, map, typeToken, callback);
		return path;
	}

	public static <T extends IResult> String getBookingList(Activity activity,
			String url, Map<String, Object> map, TypeToken typeToken,
			QJNetUICallback callback, String tokenParam) {
		if (Utils.isStringEmpty(url)) {
			url = SystemConfig.DATA_BOOKING_LIST;
		}
//		LoadingDialog.getInstance(activity).show();
		String path = URLHandler.getEncryptUrl(url + tokenParam);
		Net.with(activity).fetch(path, map, typeToken, callback);
		return path;
	}

	public static <T extends IResult> String getBookingDetail(
			Activity activity, String url, Map<String, Object> map,
			TypeToken typeToken, QJNetUICallback callback, String tokenParam) {
//		LoadingDialog.getInstance(activity).show();
		String path = URLHandler.getEncryptUrl(url + tokenParam);
		Net.with(activity).fetch(path, map, typeToken, callback);
		return path;
	}
}
